# -*- coding: utf-8 -*-

"""
Created on Fri Jun  8 18:43:24 2018

@author: Administrator
"""
#%%
import os
import glob
import shutil

#%%
class Dpabi2processing(object):
  star_nii_star = '*nii*'
  star = '*'
  underline = '_'
  def __init__(self,input_dirpath,output_dirpath):
    #search and get the input_filepaths
    input_filepaths = glob.glob(input_dirpath + os.sep + self.star + os.sep + self.star_nii_star)
    output_dirpath = output_dirpath + os.sep + os.path.split(input_dirpath)[1]
    print('output_dirpath:',output_dirpath)
    if not os.path.exists(output_dirpath):
      print('in the if')
      os.makedirs(output_dirpath)
    for input_filepath in input_filepaths:
      
      print('input_filepath:',input_filepath)
      input_dirpath,input_filename = os.path.split(input_filepath)
      input_dirname = os.path.split(input_dirpath)[1]
      output_filepath = output_dirpath + os.sep + input_dirname + self.underline + input_filename
      shutil.copy2(input_filepath,output_filepath)